package com.example.keli.ui.home.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.DensityUtil;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.base.utils.ScreenUtil;
import com.example.keli.ui.home.model.RecommendData;
import com.flyco.roundview.RoundTextView;

import java.util.List;

/**
 * description:
 * author: Allen
 * date: 2019/3/19 11:51
 */
public class HomeListAdapter extends BaseQuickAdapter<RecommendData.DataBean, BaseViewHolder> {

    int width = 173 * 2;
    int height = 220 * 2;

    public HomeListAdapter(List<RecommendData.DataBean> mData, Context context) {
        super(R.layout.item_home_list, mData);
        width = (ScreenUtil.getScreenWidth(context) - DensityUtil.dip2px(context, 30)) / 2;
        height = width * 220 / 173;
    }

    @Override
    protected void convert(BaseViewHolder helper, RecommendData.DataBean mListBean) {
        CardView cardView = helper.getView(R.id.cardview);
        cardView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
        RoundTextView roundTextView = helper.getView(R.id.tv_city);
        roundTextView.setText(mListBean.getRegion_name());
        helper.setText(R.id.poll_gift, "票数：" + mListBean.getTicket_num() + "   专属礼物：" + mListBean.getLike_num());
        helper.setText(R.id.nick_name, mListBean.getNickname());
        ImageView cover = helper.getView(R.id.iv_cover);
        GlideUtil.display(cover.getContext(), cover, mListBean.getImg());
    }

}
